package com.guit.hrms.controller;


import com.guit.hrms.dto.Position.AddPositionDTO;
import com.guit.hrms.po.position.Position;
import com.guit.hrms.po.utilsPO.Result;
import com.guit.hrms.service.PositionService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/department/position")
public class PositionController {

    @Autowired
    PositionService positionService;

    /**
     * 新增岗位
     * @param addPositionDTO
     * @return
     */
    @PostMapping
    public Result addAcademy(@Valid @RequestBody AddPositionDTO addPositionDTO){
        positionService.addAcademy(addPositionDTO);
        return Result.success();
    }

    /**
     * 更新岗位
     * @param position
     * @return
     */
    @PatchMapping
    public Result updateAcademy(@Valid @RequestBody Position position){
        if(position.getPositionId() == null){
            return Result.error("岗位id不能为空");
        }
        positionService.updateAcademy(position);
        return Result.success();
    }

    /**
     * 批量删除岗位
     * @param positionIds
     * @return
     */
    @DeleteMapping("/{positionIds}")
    public Result deleteAcademy( @PathVariable List<Integer> positionIds){

        if (positionIds == null) {
            return Result.error("请提交需要删除的岗位id");
        }
        positionService.deleteAcademy(positionIds);
        return Result.success();
    }

}
